/*
 * TreeCellRenderProperties.java
 *
 * Copyright 2011 Universidad Francisco de Paula Santander (UFPS).
 * Todos los Derechos Reservados.
 * Creado el 18/03/2011, 11:23:38 AM
 */

package com.ufps.cuatro.util.render;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.io.Serializable;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeCellRenderer;

import com.ufps.cuatro.util.InformacionNodo;
import com.ufps.cuatro.util.Utileria;

/**
 * <i><b>TreeCellRenderProperties:</b></i> @DefinicionClase
 * @author Carlos A. Torres C. - Dolly E. Guerrero. <https://code.google.com/p/tesis4dor/>
 * @version 1.0 18/03/2011
 * @see JPanel
 * @see TreeCellRenderer
 * @see Serializable
 */
public class TreeCellRenderProperties extends JPanel implements TreeCellRenderer, Serializable{
    private static final long serialVersionUID = -1644200870820278146L;
    
    private JLabel jlblEtiquetaNodo = null;
    private JLabel jlblIconoNodo = null;
    
    /**
     *@DefinicionAtributo
     */
    public final static int SIZE = 24;   
    
    /**
     * Constructor por defecto
     */
    public TreeCellRenderProperties() {        
        this.jlblEtiquetaNodo = new JLabel();
        this.jlblIconoNodo = new JLabel();        
        this.add(jlblIconoNodo);
        this.add(jlblEtiquetaNodo);
        this.setOpaque(false);             
    }    

    private void setIcono(String key, String info, boolean selected){
        ImageIcon icono = Utileria.leerRecursoImagen(key, 16);
        JLabel labelIcono = new JLabel(icono);
        this.jlblIconoNodo.setIcon(labelIcono.getIcon());
        this.jlblIconoNodo.setSize(new Dimension(TreeCellRenderProperties.SIZE, TreeCellRenderProperties.SIZE));
        this.jlblEtiquetaNodo.setText(info);
        if(selected){
            //this.jlblEtiquetaNodo.setOpaque(true);
            this.jlblEtiquetaNodo.setForeground(new Color(255,255,255));
            //this.setBackground(new Color(33,66,99));
        }
        else{
            this.jlblEtiquetaNodo.setForeground(new Color(0,0,0));
            //this.jlblEtiquetaNodo.setOpaque(false);
        }
    }    
        
    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {        
       try{
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
            Object nodeInfo = node.getUserObject();
            InformacionNodo objNodo = (InformacionNodo) nodeInfo;
            if (objNodo.getObjElemento() == null) {
                    this.setIcono(Utileria.ICONO_VACIO, objNodo.getStrIdentificador(), selected);
                }
            // Se pone el icono adecuado
            if(node.isRoot()){
                //this.setIcono(Utileria.ICONO_RAIZ_GUI, nodeInfo.toString(), selected);
            }
            else if (leaf) {
                //es una hoja, se debe evaluar el tipo

            }
            else{
                //son grupos

            }
            return this;
        }catch(java.lang.Exception ex){}
        return null;
    }
}
